//
//  SinaNewFeatureViewController.m
//  oc微博
//
//  Created by 安陆与 on 16/1/19.
//  Copyright © 2016年 安陆与. All rights reserved.
//

#import "SinaNewFeatureViewController.h"
#import "SinaNewFeatureCell.h"

@interface SinaNewFeatureViewController ()

@property (nonatomic, strong)UICollectionViewFlowLayout *layout;

@end

@implementation SinaNewFeatureViewController

static NSString * const reuseIdentifier = @"Cell";


-(instancetype)init{

    self.layout = [[UICollectionViewFlowLayout alloc]init];

    self = [super initWithCollectionViewLayout:self.layout];
    
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self setupUI];
}


-(void)setupUI{

    //注册cell
    [self.collectionView registerClass:[SinaNewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    self.collectionView.pagingEnabled = YES;
    
    self.collectionView.bounces = NO;
    
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    self.collectionView.showsVerticalScrollIndicator = NO;
    
    self.layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.layout.itemSize = self.view.bounds.size;
    
    self.layout.minimumInteritemSpacing = 0;
    
    self.layout.minimumLineSpacing = 0;
}

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SinaNewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    
    cell.backgroundColor = (indexPath.item % 2 == 0)?[UIColor redColor]:[UIColor greenColor];
    
    cell.index = (int)indexPath.item;
    
    return cell;
}


@end
